package com.jk.service.impl;

import com.jk.bean.Article;
import com.jk.bean.BiaoTi;

import com.jk.mapper.PankMapper;
import com.jk.service.PankService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import javax.annotation.Resource;
;
import java.util.ArrayList;

import java.util.List;

@Service
public class PankServiceImpl implements PankService {


    @Resource
    private PankMapper pankMapper;
    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public List<BiaoTi> queryPank() {

        List<BiaoTi> st=pankMapper.queryPank();
        List<BiaoTi> fan = new ArrayList<>();
        for (BiaoTi finance : st) {
            fan.add(finance);
            if(fan.size()>=25){
                break;
            }
        }
        return fan;
    }

    @Override
    public List<BiaoTi> queryMonth() {

        List<BiaoTi> rt= pankMapper.queryMonth();
         List<BiaoTi> obj = new ArrayList<>();

        for (BiaoTi biaoTi : rt) {

            obj.add(biaoTi);

            if(obj.size()>=25){

               break;
            }
        }
        return obj;
    }

    @Override
    public List<BiaoTi> queryDay() {

        List<BiaoTi> fg=pankMapper.queryDay();

        ArrayList<BiaoTi> gh = new ArrayList<>();

        for (BiaoTi biaoTi : fg) {
            gh.add(biaoTi);

            if(gh.size()>=25){
                break;
            }

        }
        return  gh;
    }

    @Override
    public List<Article> queryMongo(String name) {
         Query query = new Query();
        if(!StringUtils.isEmpty(name)){
            query.addCriteria(Criteria.where("btname").is(name));
        }
        return mongoTemplate.find(query,Article.class);
    }

    @Override
    public List<BiaoTi> queryAuthor(String author) {
        List<BiaoTi> au=pankMapper.queryAuthor(author);
        List<BiaoTi> title = new ArrayList<>();
        for (BiaoTi ti : au) {
            title.add(ti);
            if(title.size()>=5){
              break;
            }

        }
        return title;
    }


}
